<?php
/*
 * Created on Apr 1, 2006
 *
 */

define('GET', 'GET');
define('POST', 'POST');

 /**
  * Function to append logged in status to smarty.
  */ 
 function logged_in_status($smarty) {
 	if (isset($_SESSION['user'])) {
		$smarty->assign('logged_in', true);
		return true;
 	}
	else {
		$smarty->assign('logged_in', false);
		return false;
	}
 }
 
/**
 * That returns a user, wether it's a registered one or IP.
 */
function get_user() {
	if (isset($_SESSION['user']))
		$user = $_SESSION['user'];
	else
		$user = $_SERVER['REMOTE_ADDR'];
	return $user;
}

/**
 * Extract given keys from array.
 */
function array_extract_vars($array, $keys) {
	$result = array();
	foreach($keys as $key) {
		$result[] = isset($array[$key]) ? $array[$key] : null;
	}
	
	return $result;
}

function issetor($action, $var, $default = null) {
    if ($action == GET) 
        return isset($_GET[$var]) ? ($_GET[$var]) : $default;

    else if ($action == POST) 
        return isset($_POST[$var]) ? ($_POST[$var]) : $default;

    else {
        print("Unknown action method $action");
        assert(0);
    }
}

?>
